import React, { useState } from 'react'
import randomColor from 'random-color';

export default function ChangeBg() {
  // 声明状态保存颜色值
  let [color, setColor] = useState('#000');

  //声明变量
  function changeBg(){
    setColor(randomColor().hexString());
  }

  return (
    <div 
      onClick={changeBg}
      style={{
        width: 400,
        height: 300,
        background: color
      }}></div>
  )
}
